package com.xingge.socketio;

import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.handler.SuccessAuthorizationListener;
import com.xingge.socketio.bean.ChatBean;
import com.xingge.socketio.listener.AppAuthorizationListener;
import com.xingge.socketio.listener.AppConnectListener;
import com.xingge.socketio.listener.AppDataListener;
import com.xingge.socketio.listener.AppDisConnectListener;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class App {
	public static void main(String[] args) {
		Configuration config = new Configuration();
		config.setPort(9092);
		//增加权限监听器
		//config.setAuthorizationListener(new AppAuthorizationListener());
		
		final SocketIOServer ioServer = new SocketIOServer(config);
		//启动连接监听器
		ioServer.addConnectListener(new AppConnectListener(ioServer));
		//启动断开连接监听器
		ioServer.addDisconnectListener(new AppDisConnectListener(ioServer));
		//启动消息监听器
		ioServer.addEventListener(Config.CHATEVENT, ChatBean.class, new AppDataListener(ioServer));
		//server异步启动
		ioServer.startAsync();
		log.info("WebSocket Server is started on port {}", config.getPort());
	}
}
